<?php session_start();
if(isset($_SESSION['uid'])){
    header("Location: http://localhost:82/dtquyen-web1/filetext.php?uid=").$_SESSION['uid'];
    $_SESSION['uid']=1;
}
?>
<?php
require_once '../ptnhuan-web1/data/users.php';?>
<form method="POST">
    Username<input type="text" name="username">
    Password<input type="password" name="password">
    <input type="submit" name="submit">
</form>
<?php if (isset($_POST['submit'])): ?>
    <?php
    $username = $_POST['username'];
    $password = $_POST['password'];
    $isOke = FALSE;
    $index = -1;

    for ($i = 0; $i < count($users); $i++) {
        if ((strcmp($users[$i]['username'], $username) == 0) &&
                (strcmp($users[$i]['password'], $password) == 0)) {
            $isOk = TRUE;
            $index = $i;
            $_SESSION['uid']=$index;
        }
    }
    if ($isOk) {
        header("Location: http://localhost:82/dtquyen-web1/filetext.php?uid=".$users[$index]['id']);
    } else {
        echo 'Đăng nhập thất bại';
    }
    ?>
<?php
session_start();
if(isset($_SESSION['uid']))
  unset($_SESSION['uid']);
?>

<?php endif; ?>


